package com.bw.user.mvvm.viewmodel;

import android.view.View;
import android.widget.Button;

import androidx.annotation.NonNull;

import com.bw.mvvm_common.entity.BaseEntity;
import com.bw.mvvm_common.mvvm.utils.GreenDaoUtils;
import com.bw.mvvm_common.mvvm.viewmodel.BaseViewModel;
import com.bw.shopping.entity.ListOrder;
import com.bw.user.R;
import com.bw.user.mvvm.adapter.OrderListAdapter;
import com.bw.user.mvvm.adapter.OrderPayAdapter;
import com.bw.user.mvvm.model.OrderPayModel;
import com.bw.user.mvvm.model.entity.OrderListEntity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public
/**
 * @author Lishaohe
 * @description:
 * @date :2021/11/2 0002 下午 2:03
 *
 */
class OrderPayViewModel extends BaseViewModel<OrderPayModel> implements OnItemChildClickListener {
    public BaseQuickAdapter adapter = new OrderPayAdapter();
    @Override
    public void onCreate() {
        super.onCreate();
        adapter.setOnItemChildClickListener(this);
        requestOrderPay();
    }

    public void requestOrderPay(){
        int user_id = GreenDaoUtils.getGreenDaoUtils().green().queryBuilder().list()
                .get(0).getUser_id();
        HashMap<String,Object> map = new HashMap<>();
        map.put("orderStatus",1);
        map.put("userId",user_id);
        m.requestOrderList(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(this);
    }

    @Override
    protected void result(BaseEntity entity) {
        if (entity instanceof OrderListEntity){
            OrderListEntity orderListEntity = (OrderListEntity) entity;
            List<OrderListEntity.DataBean> data = orderListEntity.getData();
            List<ListOrder> orders = new ArrayList<>();
//            LogUtils.e("ooooooooooooooooooooooooooooooooooo"+orders);
            List<OrderListEntity.DataBean.OrderGoodsListBean> orderGoodsList = data.get(0).getOrderGoodsList();
            for (int i = 0; i < data.size(); i++) {
                for (int j = 0; j < orderGoodsList.size(); j++) {
                    ListOrder order = new ListOrder(
                            data.get(i).getOrderGoodsList().get(j).getGoods_icon(),
                            data.get(i).getOrderGoodsList().get(j).getGoods_id(),
                            data.get(i).getOrderGoodsList().get(j).getGoods_desc(),
                            data.get(i).getOrderGoodsList().get(j).getGoods_sku(),
                            data.get(i).getOrderGoodsList().get(j).getGoods_price(),
                            data.get(i).getOrderGoodsList().get(j).getGoods_count(),
                            data.get(i).getOrderGoodsList().get(j).getId(),
                            data.get(i).getOrderGoodsList().get(j).getOrder_id()
                    );
                    orders.add(order);
                }
            }


            adapter.setNewInstance(orders);

        }
    }

    @Override
    public void onItemChildClick(  BaseQuickAdapter adapter,   View view, int position) {
        int id = view.getId();

    }
}
